﻿using HuiLian.BigData.Hdl.Model;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace HuiLian.BigData.Hdl.Comparer
{
    public class HdlScadaAlarmHistoryComparer : IEqualityComparer<HdlScadaAlarmHistoryEntity>
    {
        // Products are equal if their names and product numbers are equal.
        public bool Equals(HdlScadaAlarmHistoryEntity x, HdlScadaAlarmHistoryEntity y)
        {

            //Check whether the compared objects reference the same data.
            if (Object.ReferenceEquals(x, y)) return true;

            //Check whether any of the compared objects is null.
            if (Object.ReferenceEquals(x, null) || Object.ReferenceEquals(y, null))
                return false;

            //Check whether the products' properties are equal.
            return x._id == y._id;
        }

        // If Equals() returns true for a pair of objects 
        // then GetHashCode() must return the same value for these objects.

        public int GetHashCode(HdlScadaAlarmHistoryEntity entity)
        {
            //Check whether the object is null
            if (Object.ReferenceEquals(entity, null)) return 0;

            //Get hash code for the Name field if it is not null.
            int hashProductCode = entity._id == null ? 0 : entity._id.GetHashCode();

            //Calculate the hash code for the product.
            return hashProductCode;
        }

    }
}
